package link.hwx.util;

import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;


public class beifen {
    //获取本地txt文件 启动
    public static String accountOrgID = "1002205100220031"; //核算组织
    public static String companyId = "001"; // 企业编码
    public static String orgId = "1002205100220031";//当前组织id
    public static String userId = "1002206270248073";//当前用户id
    public static String userCode = "demo2";//当前用户code
    public static String serveU9Ip = "http://192.168.0.236";//服务器ip
    public static String serveOAIp = "http://localhost:8866";//OAip
    public static String oaPrWorkflowid = "5";//请购单流程id
    public static String oaAppid = "u9"; //oaAppid
    //public static  String oaUserId = "22"; //oa加密用户id
    public static String oaPrTableDbNameD = "formtable_main_18_dt1";//oa请购单详情表
    public static String oaPrTableMainDbNameD = "formtable_main_18";//oa请购单主表

    //u9接口服务
    public static String u9ApiUrlCreatePr = "http://localhost:8881/hxw/u9/api/ucreatePr";
    public static String u9ApiUrlApprovedPr = "http://localhost:8882/hxw/u9/api/approvedPr";
    public static String u9ApiUrldelPr = "http://localhost:8883/hxw/u9/api/delPr";
    public static String u9ApiUrlQueryPr = "http://localhost:8884/hxw/u9/api/queryPr";
    public static String u9ApiUrlCreateMiscShip = "http://localhost:8885/hxw/u9/api/ucreateMiscShip";

    /* // 通过 System.getProperty("user.dir") 方式获取到项目根目录
    String projectRootDirectoryPath = System.getProperty("user.dir");
System.out.println("当前项目根目录为:\t" + projectRootDirectoryPath);
    // 通过 File 对象的 getParent() 方法获取到根目录的上级目录
    String parentPath = new File(projectRootDirectoryPath).getParent();
 */


    public static void setDataPropers() throws IOException {
        String parentPath = new File(System.getProperty("user.dir")).getParent();
        Properties prop = new Properties();
        FileInputStream inputStream = new FileInputStream(new File(parentPath + "/application.properties"));
        //properties对象读取文件输入流的数据
        prop.load(inputStream);
        inputStream.close();
        accountOrgID = prop.getProperty("accountOrgID");
        companyId = prop.getProperty("companyId");
        orgId = prop.getProperty("orgId");
        userId = prop.getProperty("userId");
        userCode = prop.getProperty("userCode");
        serveU9Ip = prop.getProperty("serveU9Ip");
        serveOAIp = prop.getProperty("serveOAIp");
        oaPrWorkflowid = prop.getProperty("oaPrWorkflowid");
        oaAppid = prop.getProperty("oaAppid");
        oaPrTableDbNameD = prop.getProperty("oaPrTableDbNameD");
        oaPrTableMainDbNameD = prop.getProperty("oaPrTableMainDbNameD");
        u9ApiUrlCreatePr = prop.getProperty("u9ApiUrlCreatePr");
        u9ApiUrlApprovedPr = prop.getProperty("u9ApiUrlApprovedPr");
        u9ApiUrldelPr = prop.getProperty("u9ApiUrldelPr");
        u9ApiUrlQueryPr = prop.getProperty("u9ApiUrlQueryPr");
        u9ApiUrlCreateMiscShip = prop.getProperty("u9ApiUrlCreateMiscShip");

        System.out.println(prop.getProperty("u9ApiUrlCreatePr"));

        File fileAl = new File(System.getProperty("user.dir") + "/src/main/resources/application.yml");
        YmlUtil.setYmlFile(fileAl);
        String u9DBUrl = prop.getProperty("u9DBUrl");
        String oaDBUrl = prop.getProperty("oaDBUrl");
        YmlUtil.saveOrUpdateByKey("spring.datasource.dynamic.datasource.U9CTest.url", u9DBUrl);
        YmlUtil.saveOrUpdateByKey("spring.datasource.dynamic.datasource.OAData.url", oaDBUrl);


    }


    public void run(String... args) throws Exception {
        setDataPropers();
    }


}
